// pages/sbzgl/sbzgl.js
const app =getApp()
Page({
  
    data: {
     imgList: [],
     foundimage: [],
     foundinformation: [],
     foundphone: [],
     foundtitle: [],
     tt : '',
     picker : ['失物', '招领'],
      listtype:'',
    },
    textareaBInput1(e) {
      this.setData({
        textareaBValue: e.detail.value,
        foundtitle: e.detail.value
      })
    },
    textareaBInput2(e) {
      this.setData({
        textareaBValue: e.detail.value,
        foundaddress: e.detail.value
      })
    },
    textareaBInput3(e) {
      this.setData({
        textareaBValue: e.detail.value,
        foundinformation: e.detail.value
      })
    },
    textareaBInput4(e) {
      this.setData({
        textareaBValue: e.detail.value,
        foundphone: e.detail.value
      })
    },
    ViewImage(e) {
      wx.previewImage({
        urls: this.data.imgList,
        current: e.currentTarget.dataset.url
      });
    },
    ChooseImage() {
      wx.chooseImage({
          count: 1, //默认9
          sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
          sourceType: ['album','camera'],
          success : (res) => {
            const tempFilePaths = res.tempFilePaths
            wx.uploadFile({
              url: 'https://www.woodymidnight.cn/BCUHelper/api/file/uploadFile', //仅为示例，非真实的接口地址
              filePath: tempFilePaths[0],
              name: 'file',
              success: (res) => {
                  console.log(res);
                  res = JSON.parse(res.data)
                  this.data.imgList.push(res.data.fileUrl)
                  this.data.foundimage.push(res.data.fileUrl)
                  this.setData({
                      imgList: this.data.imgList,
                      foundimage: this.data.foundimage
                  })
                }
            })
          }
        })
    },
    fabuzl:function(){
      var that = this;
    wx.request({
      url: 'https://www.woodymidnight.cn/BCUHelper/api/found/insertfound',  
      method: 'POST',
      data:{
        foundtitle : this.data.foundtitle,
        foundaddress : this.data.foundaddress,
        foundimage : this.data.foundimage[0],
        foundphone : this.data.foundphone,
        foundinformation : this.data.foundinformation,
        userid : app.data.userInfo.userid,
        userimage : app.data.userInfo.userimage,
        username : app.data.userInfo.username,
        foundtype : this.data.listtype
      },                                      
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function(res) { 
        that.setData({
          tt: res.data
        })
        console.log(res.data);
        wx.navigateBack({
          delta: 1,
        })
      },
      fail: function(res) {
        console.log("失败");
      }
    })
  },

  PickerChange(e) {
    console.log(e.detail.value);
    let x = parseInt(e.detail.value)
    this.setData({
      listtype: x
    })
  },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})